import os
import time

from nes_py.wrappers import JoypadSpace
import gym_super_mario_bros
from gym_super_mario_bros.actions import SIMPLE_MOVEMENT
from gym import wrappers


videoPath="./.gym-results"
#使用gym_super_mario_bros包函数创建游戏环境env
env = gym_super_mario_bros.make('SuperMarioBros-v0')
#指定环境为简单模式（动作简化，去除一些左上、左下等复杂动作）
env = JoypadSpace(env, SIMPLE_MOVEMENT)

# #录屏
# env = wrappers.Monitor(env,videoPath, force=True)

#执行5000个简单的向右随机操作
done = True #游戏结束标志
for step in range(5000):
    env.render()
    if done:
        #如果游戏结束则重置：
        state = env.reset()
    state, reward, done, info = env.step(env.action_space.sample())

# 关闭创建的游戏env
env.close()

if __name__ == '__main__':
    pass